package com.view;

import javax.swing.*;
import java.awt.*;
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;
/**
 * @Description: 
 * @Param: 
 * @return: 
 * @Author: lhh
 * @Date: 2022/6/12
 */

//public class TestView {
    //public static void main(String[] args) throws InterruptedException{
        //RockpaperscissorWindow window = new RockpaperscissorWindow("石头剪刀布");
        //window.setVisible(true);


       // Thread.sleep(6000);//程序睡6s 6000ms
       // window.setVisible(false);

   // }
//}
import java.awt.Component;
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;
import javax.swing.JComboBox;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;

public class TestView {
    public TestView() {
    }

    public static void main(String[] args) {
        JFrame jf = new JFrame("测试窗口");
        jf.setSize(250, 250);
        jf.setLocationRelativeTo((Component)null);
        jf.setDefaultCloseOperation(3);
        JPanel panel = new JPanel();
        JLabel label = new JLabel("用户：");
        panel.add(label);
        String[] listData = new String[]{"人1", "电脑1", "人2", "电脑2"};
        final JComboBox<String> comboBox = new JComboBox(listData);
        comboBox.addItemListener(new ItemListener() {
            public void itemStateChanged(ItemEvent e) {
                if (e.getStateChange() == 1) {
                    System.out.println("选中: " + comboBox.getSelectedIndex() + " = " + comboBox.getSelectedItem());
                }

            }
        });
        comboBox.setSelectedIndex(2);
        panel.add(comboBox);
        jf.setContentPane(panel);
        jf.setVisible(true);
    }
}

